package com.yf.yfwebview.mainprocess

import android.util.Log
import com.yf.yfwebview.IWebViewHandleCommondInterface
import com.yf.yfwebview.command.Command
import java.util.ServiceLoader

class WebViewCommandManger:IWebViewHandleCommondInterface.Stub() {
    private val commandMap:MutableMap<String, Command> = mutableMapOf()

    init {
        val serviceLoader = ServiceLoader.load(Command::class.java)
        serviceLoader.forEach {
            if (!commandMap.containsKey(it.name())){
                commandMap[it.name()] = it
            }
        }
    }


    override fun handleCommond(name: String, pamares: String) {
        Log.i("TAG----", "handleCommond: $name")
        commandMap[name]?.handleCommand(name,pamares)
    }
}